package insight.google.game.era.bo.card;

import java.util.ArrayList;
import java.util.List;

import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.Key;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;

import insight.google.game.era.bo.GameUser;
import insight.google.game.era.core.Util;
import insight.google.game.era.data.Card;

import org.directwebremoting.annotations.DataTransferObject;

@DataTransferObject
public class RoleCard extends Card {

	/**
	 * 
	 */
	public static final String KING = "King";
	public static final String SUPPORTER = "Supporter";
	public static final String REBEL = "Rebel";
	
	public static final String TRAITOR = "Traitor";
	
	
	
	@Persistent(mappedBy="roleCard")
	private GameUser user;
	
	
//	@Persistent
//	private Key userId;
	
	
	public RoleCard(String cardId, String cardName) {
		this.id = cardId;
		this.name = cardName;
	}
	
	
	
	
	
	
	public GameUser getUser() {
		return user;
	}






	public void setUser(GameUser user) {
		this.user = user;
	}






	public static List<RoleCard> getRoleCards(int noOfUsers){
		List<RoleCard> roleCardList = new ArrayList<RoleCard>();
		String[] roleCardsTitle = {RoleCard.KING,RoleCard.REBEL+"1",RoleCard.SUPPORTER+"1",RoleCard.TRAITOR+"2",RoleCard.SUPPORTER+"2",RoleCard.REBEL+"2"};
//		for (int i = 0; i < noOfUsers; i++) {
//			roleCardList.add(new RoleCard(roleCardsTitle[i],roleCardsTitle[i]));
//		}
		RoleCard kingCard = new RoleCard(RoleCard.KING,RoleCard.KING);
		roleCardList.add(kingCard);
		
		RoleCard rebelCard1 = new RoleCard(RoleCard.REBEL+"1",RoleCard.REBEL);
		roleCardList.add(rebelCard1);
		if(noOfUsers > 2){
			RoleCard supporterCard1 = new RoleCard(RoleCard.SUPPORTER+"1",RoleCard.SUPPORTER);
			roleCardList.add(supporterCard1);
		}
		
		if(noOfUsers > 3){
			RoleCard taritorCard = new RoleCard(RoleCard.TRAITOR+"1",RoleCard.TRAITOR+"1");
			roleCardList.add(taritorCard);
		}
		

		if(noOfUsers > 4){
			RoleCard rebelCard2 = new RoleCard(RoleCard.REBEL+"2",RoleCard.REBEL);
			roleCardList.add(rebelCard2);
		}
		if(noOfUsers > 5){
			RoleCard supporterCard2 = new RoleCard(RoleCard.SUPPORTER+"2",RoleCard.SUPPORTER);
			roleCardList.add(supporterCard2);
		}
		if(noOfUsers > 6){
			RoleCard rebelCard3 = new RoleCard(RoleCard.REBEL+"3",RoleCard.REBEL);
			roleCardList.add(rebelCard3);
		}
		if(noOfUsers > 7){
			RoleCard taritorCard2 = new RoleCard(RoleCard.TRAITOR+"2",RoleCard.TRAITOR);
			roleCardList.add(taritorCard2);
		}
		
		
		Util.shuffleCards(roleCardList,1);
		return roleCardList;
	}
	
	public static RoleCard getRoleCardById(String cardId){
		String[] roleNames = cardId.split("_");
		return new RoleCard(cardId, roleNames[0]);
	}






//	public Key getUserId() {
//		return userId;
//	}
//
//
//
//
//
//
//	public void setUserId(Key userId) {
//		this.userId = userId;
//	}
}
